'
' Copyright (c) 2004-2005
' by Peter Donker ( info@bring2mind.net )
'
' Permission is hereby granted to use and/or modify this software for a single server. It is 
' NOT permitted to publish, distribute, sublicense, and/or sell copies of this software in its
' original or modified form. You are not allowed to remove this copyright notice.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
' BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
' NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
' DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THE SOFTWARE.
'
Imports DotNetNuke.Services.Localization.Localization
Imports Bring2mind.DNN.Modules.Guestbook
Imports Bring2mind.DNN.Modules.Guestbook.Business

Namespace Bring2mind.DNN.Modules.Guestbook.Controls

 Public Class ModuleBase
  Inherits DotNetNuke.Entities.Modules.PortalModuleBase

#Region " Variables "
  Private _settings As ModuleSettings
#End Region

#Region " Properties "
  Public Property ModuleSettings() As ModuleSettings
   Get

    If _settings Is Nothing Then
     Dim CacheKey As String = "Settings4Module" & Me.ModuleId & "inPortal" & Me.PortalId & "User" & Me.UserId.ToString
     Try
      _settings = CType(Me.Session.Item(CacheKey), ModuleSettings)
     Catch ex As Exception
     End Try
     If _settings Is Nothing Then
      _settings = New ModuleSettings(ModuleId)

      ' Determine add capability
      If _settings.Roles.IndexOf(DotNetNuke.Common.glbRoleAllUsers & ";") < 0 Then
       Dim AddRoles() As String = _settings.Roles.Split(New Char() {";"c})
       Dim AddRole As String
       Dim rc As New DotNetNuke.Security.Roles.RoleController, ur As Entities.Users.UserRoleInfo
       For Each AddRole In AddRoles
        Try
         ur = rc.GetUserRole(PortalId, UserId, Integer.Parse(AddRole))
         If Not ur Is Nothing Then
          _settings.CanAdd = True
          Exit For
         End If
        Catch ex As Exception
        End Try
       Next
      Else
       _settings.CanAdd = True
      End If

      ' Determine approve capability
      If Not _settings.AutoApprove Then
       Try
        Dim rc As New DotNetNuke.Security.Roles.RoleController, ur As Entities.Users.UserRoleInfo
        ur = rc.GetUserRole(PortalId, UserId, _settings.ApprovalRole)
        If Not ur Is Nothing Then
         _settings.CanApprove = True
        End If
       Catch ex As Exception
       End Try
      End If

      Me.Session.Add(CacheKey, _settings)
     End If
    End If

    Return _settings

   End Get
   Set(ByVal Value As ModuleSettings)
    _settings = Value
   End Set
  End Property

  Public ReadOnly Property PicturePath() As String
   Get
    Return Me.PortalSettings.HomeDirectory & "GuestbookPictures/" & ModuleId.ToString & "/"
   End Get
  End Property

  Public ReadOnly Property PictureMapPath() As String
   Get
    Return Me.PortalSettings.HomeDirectoryMapPath & "GuestbookPictures\" & ModuleId.ToString & "\"
   End Get
  End Property

  Public ReadOnly Property ThumbnailPath() As String
   Get
    Return Me.PortalSettings.HomeDirectory & "GuestbookPictures/" & ModuleId.ToString & "/Thumbs/"
   End Get
  End Property

  Public ReadOnly Property ThumbnailMapPath() As String
   Get
    Return Me.PortalSettings.HomeDirectoryMapPath & "GuestbookPictures\" & ModuleId.ToString & "\Thumbs\"
   End Get
  End Property

#End Region

#Region " Public Methods "
  Public Function GetNewFilename(ByVal Extension As String) As String
   Dim Filename As String = Format(Now, "yyyyMMdd-hhmm") & "-"
   Dim i As Integer = 0
   Do While IO.File.Exists(PictureMapPath & Filename & i.ToString & Extension)
    i += 1
   Loop
   Return Filename & i.ToString & Extension
  End Function
#End Region


 End Class

End Namespace



